<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2007/02/20 07:58:04 $)
// $RCSfile: index.php,v $ : $Revision: 1.12 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

define("SWIFT_AREA", 40);

require_once ("./swift.php");

/**
* ###############################################
* CSS OUTPUT
* ###############################################
*/
if ($_REQUEST["_ca"] == "css") {
	$template->cache(array('clientcss'));
	header("Content-Type: text/css");
	headerCache();

	echo $template->displayTemplate("clientcss");
	exit;


/**
* ###############################################
* Other Action
* ###############################################
*/
} else {
	if (!$session->start(SESSION_CLIENT)) {
		// Failed to load session, Create a fresh session over here.
		$session->insertSession(SESSION_CLIENT, 0);
	}

	if (defined("ISMODERNBILL") && (empty($_SWIFT["session"]["typeid"])))
	{
		$loginresult = $loginshare->authorize($_SESSION["client_email"], $_SESSION["client_password"]);
		if (!$loginresult)
		{
			echo "MB Core Error: Unable to continue, Login Failed";
			exit;
		}
	} else if (defined("ISMODERNBILLV5") && (!empty($CONF["user"]["username"]))) {
		$loginresult = $loginshare->authorize($CONF["user"]["username"], $CONF["user"]["password"]);
		if (!$loginresult)
		{
			echo "MB v5 Core Error: Unable to continue, Login Failed";
			exit;
		}
	}

	// ======= LOAD THE USER CREDENTIALS FROM ACTIVE LOGINSHARE MODULE =======

	loginShareLoadUser(); // Loads up user data from active loginshare module

	$loginshare->processUserGroup(); // Checks to see of empty user groups and loads default ones

	$loginshare->loadPermissions(); // Loads up the permissions for active user group

	// ======= MISC ACTIONS =======
	$loginemailcookie = $cookie->getSCookie("loginemail");
	if (!empty($loginemailcookie) && $_SWIFT["user"]["loggedin"] == false)
	{
		$loginpasscookie = $cookie->getSCookie("loginpassword");
		$template->assign("cookieloginemail", $loginemailcookie);
		$template->assign("cookieloginpassword", $loginpasscookie);
		$template->assign("cookierememberme", "1");
	}

	// ======= PROCESS THE WIDGETS =======
	require_once ("./includes/Widgets/widgets.php");
	$template->assign("widgets", processWidgets($_widgets));

	if (empty($_SWIFT["user"]["userid"]) && !empty($_SERVER["QUERY_STRING"]))
	{
		$template->assign("querystring", iif(!stristr($_SERVER["QUERY_STRING"], "logout"), $_SERVER["QUERY_STRING"]));
	}

	// ======= TRY TO EXECUTE ANY ASSOCIATED EVENTS =======
	if (!$events->triggerEvent(EVENT_CLIENT))
	{
		// Load main page
		require_once ("./modules/core/client_index.php");
	}
}
?>